package me.itxuye.moment.ui.activity;

import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import butterknife.Bind;
import me.itxuye.moment.R;
import me.itxuye.moment.base.BaseActivity;

public class MainActivity extends BaseActivity {

  @Bind(R.id.id_drawer_layout) DrawerLayout drawerLayout;
  @Bind(R.id.id_nv_menu) NavigationView navigationView;
  @Bind(R.id.id_toolbar) Toolbar toolbar;

  @Override protected int provideContentViewId() {
    return R.layout.activity_main;
  }

  @Override protected void initView() {

    initToolBar();
  }

  private void initToolBar() {

    setSupportActionBar(toolbar);
    final ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu_white_24dp);
    ab.setDisplayHomeAsUpEnabled(true);

    setupDrawerContent(navigationView);
  }

  private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(

        new NavigationView.OnNavigationItemSelectedListener() {

          private MenuItem mPreMenuItem;

          @Override public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (mPreMenuItem != null) mPreMenuItem.setChecked(false);
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            mPreMenuItem = menuItem;
            return true;
          }
        });
  }

  @Override protected void setListener() {

  }

  @Override protected void initData() {

  }

  @Override protected void getIntentData(Bundle saveInstance) {

  }

  @Override public void onClick(View v) {

  }

  @Override public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_drawer, menu);
    return true;
  }

  @Override public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
      drawerLayout.openDrawer(GravityCompat.START);
      return true;
    }
    return super.onOptionsItemSelected(item);
  }
}
